import {MiddlewareConsumer, Module, NestModule, RequestMethod} from '@nestjs/common'
import {LoggerMiddleware} from './logger.middleware'
import {TimeMiddleware} from './time.middleware'
import {LoggerFunMiddleware} from './logger.fun.middleware'
import {CatsModule} from './cats/cats.module'
import {AppController} from './app.controller'
import {AppService} from './app.service';

@Module({
    imports: [CatsModule],
    controllers: [AppController],
    providers: [AppService],
})
// export class AppModule {}
export class AppModule implements NestModule {
    configure(consumer: MiddlewareConsumer): any {
        consumer
            .apply(LoggerMiddleware,TimeMiddleware)         // 多个中间件，response.send返回会错误
            // .forRoutes('app-cats')       //匹配前缀的
            // .forRoutes({
            //     path: 'app-cats',           //只有这个路由才会触发中间件
            //     // method: RequestMethod.POST,         //cats路由是get请求，这里设置post没有匹配到不执行中间件
            //     method: RequestMethod.POST,
            // })
            // .forRoutes('start*bb')           //通配符
            .exclude(
                {path:'app/startooobb',method:RequestMethod.POST,}
            )
            .forRoutes(AppController)           // 传递控制器,只要是这个控制器前缀下的路由都会执行
    }
}
